<template>
  <div class="swiper-container">
    <div class="swiper-wrapper" :style="{'transform': `translateX(${translateX}px)`}">
      <div class="swiper-slide" v-for="(item, index) in randShop" :key="index" @click="handleItemClick(item.id)">
        <div class="store">
          <div class="store-item flex-center">
            <div class="store-top flex-start">
              <img :src="item.avatar"
                alt="">
              <div class="store-top-title">
                <div class="store_title"><h2>{{ item.title }}</h2></div>
                <div class="flex-between">
                  <div>
                    <div class="store-top-introduce"><span>商品:</span><span>{{item.count}}</span></div>
                    <div class="store-top-introduce"><span>销量 :</span><span>{{item.sales_data}}</span></div>
                    <div class="store-top-introduce"><span>信用分:</span><span>{{item.xinyufen}}</span></div>
                  </div>
                  <button type="button" class="el-button el-button--default"><!---->
                    <!----><span> {{ $t('HomeStoreBtn') }} &gt; </span></button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onUnmounted } from 'vue'
import { useRouter } from "vue-router";
const props = defineProps({
  randShop: {
    type: Array,
    default: () => {
      return []
    }
  }
})
const router = useRouter()
const length = ref(10)
const moveNumber = ref(0)
const translateX = ref(0)
const timer = ref(null)
if(props.randShop.length > 3) {
  timer.value = setInterval(() => {
      if(moveNumber.value === props.randShop.length - 3) {
        moveNumber.value = 0
        translateX.value = 0
      }else {
        moveNumber.value++
        translateX.value = -moveNumber.value * 430
      }
  }, 3000)
}
// (props.randShop.length > 3) && (timer.value = setInterval(() => {
//   if(moveNumber.value === props.randShop.length - 3) {
//     moveNumber.value = 0
//     translateX.value = 0
//   }else {
//     moveNumber.value++
//     translateX.value = -moveNumber.value * 430
//   }
// }, 3000))
const handleItemClick = (id) => {
  router.push('/store?id='+id)
}
onUnmounted(() => {
  clearInterval(timer.value)
})
</script>
<style scoped>
.swiper-container{
  overflow: hidden;
}
.swiper-wrapper{
  display: flex;
  transition: all 0.5s ease-in-out;
}
.swiper-slide{
  width: 340px;
  margin-right: 90px;
  flex-shrink: 0;
}
.main-store {
  margin-top: 26px;
  margin-bottom: 26px
}

.main-store-title h1 {
  font-weight: 700;
  font-size: 16px;
  color: var(--color-grey);
  margin: 24px 0
}

.main-store-title .all,.main-store-title span {
  color: var(--color-main);
  font-size: 12px
}

.main-store-title .all {
  cursor: pointer;
  font-weight: 400
}

.main-store-content {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(188px,165px));
  grid-column-gap: 14px;
  grid-row-gap: 20px;
  align-content: center
}
.store .store_title {
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  overflow: hidden;
  -webkit-box-orient: vertical
}

.store:hover .store-item {
  border: 1px solid var(--color-main)
}

.store-item {
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: 4px
}

.store-top {
  width: 100%;
  padding: 15px
}

.store-top img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  -o-object-fit: cover;
  object-fit: cover
}

.store-top-title {
  flex: 1;
  margin-left: 15px
}

.store-top-title h2 {
  font-weight: 400;
  font-size: 14px;
  color: var(--color-black);
  margin-bottom: 6px
}

.store-top-title .el-button {
  background: #fcf2e2;
  color: var(--color-main);
  border: 1px solid var(--color-main);
  border-radius: 27px;
  font-size: 12px;
  padding: 5px 10px;
  white-space: inherit;
  width: 118px
}

.store-top-title>div {
  width: 100%
}

.store-top-introduce {
  font-weight: 400;
  font-size: 12px;
  color: var(--color-title)
}

.store-top-introduce span:first-child {
  padding-right: 4px
}

.store-bottom {
  margin-top: 20px;
  padding: 10px
}

.store-bottom-left {
  width: 173px;
  height: 163px;
  position: relative
}

.store-bottom-left img {
  max-width: 173px;
  max-height: 163px;
  width: 100%;
  height: 100%;
  border-radius: 4px
}

.store-bottom-right {
  display: flex;
  justify-content: flex-start;
  align-content: center;
  flex-direction: column;
  flex: 1;
  margin-left: 5px;
  height: 163px
}

.store-bottom-item {
  position: relative;
  flex: 1;
  margin-bottom: 5px
}

.store-bottom-item img {
  flex: 1;
  width: 100%;
  height: 100%;
  border-radius: 4px
}

.store-bottom-item:last-child {
  margin-bottom: 0
}

.store-bottom .amount {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 80px;
  height: 29px;
  line-height: 29px;
  font-weight: 500;
  font-size: 16px;
  color: var(--color-main);
  background: var(--color-white);
  opacity: .78;
  border-radius: 0 0 0 4px;
  text-align: center
}
</style>